package com.example.libretranslatemobile.settings;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.example.libretranslatemobile.R;
import com.example.libretranslatemobile.settings.connection.ConnectionActivity;

import java.util.ArrayList;


public class SettingsAdapter extends RecyclerView.Adapter<SettingsAdapter.SettingViewHolder> {

    int numberItems;
    ArrayList<String> itemText;

    public SettingsAdapter(int numberItems, ArrayList<String> itemText){
        this.numberItems = numberItems;
        this.itemText = itemText;
    }

    @NonNull
    @Override
    public SettingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.settings_item, parent, false);

        return new SettingViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull SettingViewHolder holder, int position) {
        holder.settingsRvTextView.setText(itemText.get(position));

        if(position == 0){
            View.OnClickListener onClickListener = new View.OnClickListener(){

                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(holder.settingsRvTextView.getContext(), ConnectionActivity.class);
                    ContextCompat.startActivity(holder.settingsRvTextView.getContext(), intent, new Bundle());
                }
            };
            holder.settingsRvTextView.setOnClickListener(onClickListener);
        }
    }

    @Override
    public int getItemCount() {
        return numberItems;
    }

    static class SettingViewHolder extends RecyclerView.ViewHolder{

        TextView settingsRvTextView;

        public SettingViewHolder(@NonNull View itemView) {
            super(itemView);

            settingsRvTextView = itemView.findViewById(R.id.settings_rv_text_view);


        }
    }
}
